 <template>
    <div class="index-page">
        <!-- 顶部按钮 -->
        <div class="but1">
        <router-link to="/home">
			<el-button type="warning" size="small" class="add btn"  style='margin-right: 5px;' icon="el-icon-menu">首页</el-button>
		</router-link>
	    <el-button type="success" size="small" class="add btn" @click='componentsShow("add")' icon="el-icon-edit">添加评价模版</el-button>
	    <router-link to="/admin/pingjiasend">
			<el-button type="success" size="small" class="add btn"  style='margin-right: 5px;' icon="el-icon-view">查看老师评价</el-button>
		</router-link>
        </div>
        <!-- 模糊搜索条件 -->
        <div class="search">
            <div class="search-item">
                <el-input placeholder="按模板名称搜索" class="code-search" v-model="vkeyword" icon="search" @keyup.enter.native="search"></el-input>
            </div>
        <el-button type="primary" class="add btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
        </div>

        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            border
            stripe
            size="small"
            align="left"
            class="admin-table"
            @select="checkSelect"
            @select-all="checkall">
            <!--<el-table-column type="selection" width="55"></el-table-column>-->
           <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)">
                        {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
			         <!-- <el-table-column label="操作" width="160" align="center"> -->
           <el-table-column  fixed="right" align="center"  label="操作"  width="230px">
                <template scope="scope">
                    <!-- v-if="scope.row.qx == 'Y'"-->
                  <router-link :to="{path:'/admin/pingjiasend',query: {mbid:scope.row.id,frompage:'lspj'}}">
                  <el-button size="small" class="add btn" type="success">发起老师评价</el-button>
		          </router-link>
                  
                  <el-dropdown>
	                     <el-button type="primary" size="mini"> 更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
						 <el-dropdown-menu slot="dropdown">
						    <el-dropdown-item><el-button size="mini" type="warning"  @click="componentsShow('edit',scope)">编辑</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini" type="success"  @click="componentsShow('info',scope)">预览</el-button></el-dropdown-item>
						    <el-dropdown-item><el-button size="mini"  type="danger"  @click="componentsShow('yc',scope)">删除</el-button></el-dropdown-item>
						 </el-dropdown-menu>
					 </el-dropdown>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>


        <!-- 各个组件显示区域 -->

        <!-- 编辑组件 -->
        <AddComponent v-if="portComponents.add.toggle"  @close="componentsHide"  ></AddComponent>
        <!-- 编辑组件 -->
        <EditComponent v-if="portComponents.edit.toggle"  @close="componentsHide"  :params="portComponents.edit.params"></EditComponent>
        <!-- info组件 -->
        <infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
        
      <!-- 单独删除组件 -->
        <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide"  :data="portComponents.singleDelete.data"></DeleteComponent>
        <!-- 批量删除组件 -->
        <DeleteComponent v-if="portComponents.multipleDelete.toggle"  @close="componentsHide"  :data="portComponents.multipleDelete.data"></DeleteComponent>
        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>

<script>
    import Vue from 'vue'
    import AddComponent from './add'
    import EditComponent from './edit'
    import InfoComponent from './info'
    import DeleteComponent from './del'
     import qs from 'qs'
    export default {
        components: {
            DeleteComponent,
            AddComponent,
            EditComponent,
            InfoComponent
        },
        data () {
            return {
                type: '',
                vkeyword: '',
                /*组件区域*/
                portComponents: {
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该条数据, 是否继续?'
                        }
                    },
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的数据, 是否继续?'
                        }
                    },
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    edit: {
                        type: 'edit',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    info: {
                        type: 'info',
                        toggle: false,
                        params: '',
                        data: {}
                     }

                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列   0是隐藏  1是显示
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                    formatter: function (row, column) {}
                */
                portTitleList: [
                    {
                        prop:'xxid',
                        label:'xxid',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'',
                        headerAlign:'center'
                      },
                      {
                          prop:'mc',
                          label:'模板名称',
                          hide:1,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'lx1',
                          label:'评价项目',
                          hide:1,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'lx2',
                          label:'评价项目2',
                          hide:0,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'lx3',
                          label:'评价项目3',
                          hide:0,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'lx4',
                          label:'评价项目4',
                          hide:0,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'lx5',
                          label:'评价项目5',
                          hide:0,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'note',
                          label:'备注',
                          hide:1,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'pjgz',
                          label:'评价规则',
                          hide:1,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      },
                      {
                          prop:'sj',
                          label:'创建时间',
                          hide:0,
                          align:'center',
                          fixed:false,
                          width:'',
                          minWidth:'',
                          headerAlign:'center'
                      }

                ],

                /*动画加载*/
                isLoading: false,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputbjmc:'' , //  班级名称,


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //
            }
        },
        created () {

            //加载页面时调用
            this.$store.dispatch('changeTitle','评价老师模板列表');//修改title
            this.$store.dispatch('changeRouterIndex', '/admin/pingjia');//修改路由

            this.search();//分页获取默认数据
            // this.getdropDownData();//获取下拉框数据

        },
        methods: {
        	  cancelf () {
            //sonpage 关闭
          this.$store.dispatch('changeTitle','首页');//修改title
          // this.params.toggle = false;
//          this.$emit('close',{type:'time',cancel:true})
          },
            search () {//查询搜索触发事件
            	var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                      keyword: this.vkeyword, // keyword
                      yhid:logininfo.id,
                      xxid:logininfo.xxid,
                      pageindex: this.pageindex,
                      pagesize: this.pagesize
               })
             //执行
                 this.axios.post(this.$store.state.api + 'xspjlsmb/list',  params2 )
                 .then(res => {
//               	console.log(res,'jjjj')
                  let data = res.data.data;
                  let list = data.list;
                  this.total = data.totalPage;
                  this.dataList = list;
                  this.searchLoading = false;
                 }).catch(res => {
                  this.searchLoading = false;
				})				
            },
            tableCellControl (scope) {
            //表格单元格控制CSS样式
              /*  if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
           },
            handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },

            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                // console.log(selection)
                let strID = [];

                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                // console.log(strID.join(","))
                this.multipleDelNum = strID.join(",");
                // console.log(strID)
            },







            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {

                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;

                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id

                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;

                        }else if(this.portComponents[i].type == 'test'){
                            this.portComponents[i].data.distinction  = "test";

                        }else if(this.portComponents[i].type == 'score'){
                            this.portComponents[i].data.distinction  = "score";

                        }else{
                            return;
                        }
                        return;
                    }
                }

            },
            componentsHide (setting) { //关闭组件
                console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;

                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }
        },
        computed: {
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .index-page {
        font-size:12px;
        position: relative;

        .btn {
            height: 30px;
            padding:0 10px;
        }
         .but1{
			width: 40%;
			height: 50px;
			line-height: 50px;
			float: left;
		}
		.search{
			width: 60%;
			height: 50px;
			line-height: 50px;
			float: right;
			text-align: right;
		}
        .classInfo:hover {
            color:#4094c7;
            cursor:pointer;
            text-decoration: underline;
        }

        .code-search {
			 max-width: 130px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
		}

        .change-time{
            width: 480px;
            display: inline-block;
        }

        .class-page {
            text-align: left;
            margin-top:10px;
        }

        .search-item {
            display: inline-block;
        }

        h2{
            line-height: 40px;
        }
        .el-button+.el-button {
     margin-left: 0px; 
        }
        

    }
</style>
